﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace Motoball
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Camera : GameComponent
    {
        public Matrix view { get;  set; }
        public Matrix projection { get; protected set; }
        public Vector3 pos;
        public Vector3 target;
        public Vector3 up;

        public Matrix menuView;
        public Matrix gameplayView;
        public static float gameplayCamDistance;

        public Camera(Game game, Vector3 pos, Vector3 target, Vector3 up)
            : base(game)
        {
            this.pos = pos;
            this.target = target;
            this.up = up;

            menuView = Matrix.CreateLookAt(pos, target, up);
            menuView *= Matrix.CreateTranslation(-450, 80, 250);
            menuView *= Matrix.CreateRotationY(-0.45f);
            gameplayCamDistance = ContentStorage.CurrentRingSize * 3.1f;
            gameplayView = Matrix.CreateLookAt(new Vector3(float.Epsilon, gameplayCamDistance, -1), new Vector3(0, 0, 0), Vector3.Up);
            view = menuView;

            projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4,
                //(float)Game.Window.ClientBounds.Width /
                //(float)Game.Window.ClientBounds.Height,
                720f/
                408f,
                1, 20000);
        }

        #region Methods
        public override void Initialize()
        {
            base.Initialize();
        }
       
        public override void Update(GameTime gameTime)
        {
            KeyboardState state = Motoball.screenManager.Input.CurrentKeyboardStates[0];

            if (state.IsKeyDown(Keys.R))
                view *= Matrix.CreateRotationX(-0.02f);
            if (state.IsKeyDown(Keys.F))
                view *= Matrix.CreateRotationX(0.02f);
            if (state.IsKeyDown(Keys.Q))
                view *= Matrix.CreateRotationY(-0.02f);
            if (state.IsKeyDown(Keys.E))
                view *= Matrix.CreateRotationY(0.02f);
            if (state.IsKeyDown(Keys.Y))
                view *= Matrix.CreateRotationZ(-0.02f);
            if (state.IsKeyDown(Keys.X))
                view *= Matrix.CreateRotationZ(0.02f);
            if (state.IsKeyDown(Keys.W))
                view *= Matrix.CreateTranslation(0, 0, 50);
            if (state.IsKeyDown(Keys.B))
                view *= Matrix.CreateTranslation(0, 0, -50);
            if (state.IsKeyDown(Keys.T))
                view *= Matrix.CreateTranslation(0, 0, 5);
            if (state.IsKeyDown(Keys.Z))
                view *= Matrix.CreateTranslation(0, 0, -5);

            
            

            base.Update(gameTime);
        }

        #endregion
    }
}
